package edu.bupt.threadpool;

import java.util.Random;
import java.util.concurrent.BlockingQueue;

public class WriteHandler implements Runnable{

	/**
	 * @param args
	 */
	private BlockingQueue<String> fQueue;
	public WriteHandler(BlockingQueue<String> fQueue){
		this.fQueue = fQueue;
	}

	@Override
	public void run() {
		while(true){
			if(fQueue.isEmpty())
				try {
					System.out.println("fqueue is empty!");
					Thread.sleep(1000);
					continue;
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			for(int i = 0; i < 50; i++){
				if(fQueue.isEmpty())
					break;
				try {
					System.out.println("write: " + fQueue.take());
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			try {
				Thread.sleep(new Random().nextInt(400)+100);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		
	}

}
